package top.finen.miniweapp.service.impl;

import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import top.finen.miniweapp.service.UrlRequestService;

@Service
public class UrlRequestServiceImpl implements UrlRequestService {


    @Override
    public String httpClient(String url) {
        RestTemplate restTemplate = new RestTemplate();

        ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
        //如果获取到数据则将数据进行返回，如果没有获取到数据则返回错误信息
        if (response.getStatusCode() == HttpStatus.OK) {
            return response.getBody();
        } else {
            return "未获取到数据";
        }
    }
}
